@extends('admin.layout.base')

@section('content')

    <div class="layui-form-item">
        <div class="layui-inline">
            <input class="layui-input search-data" name="title" placeholder="帖子标题" autocomplete="off">
        </div>

        <div class="layui-inline layui-form">
            <select name="status" class="search-data">
                <option value="">状态</option>
                <option value="0">已通过</option>
                <option value="1">待审核</option>
                <option value="2">已拒绝</option>
            </select>
        </div>

        <div class="layui-inline demoTable">
            <button class="layui-btn layui-btn-sm layuiadmin-btn-useradmin" data-type="search" lay-filter="search">
                <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
            </button>
        </div>
    </div>

    <div class="layui-card">

        <table class="layui-hide" id="tableData" lay-filter="myTable"></table>

        <script type="text/html" id="tag">
            @{{# if(d.status == 0){ }} <span class="layui-badge layui-bg-green">已通过</span> @{{# } }}
            @{{# if(d.status == 1){ }} <span class="layui-badge layui-bg-cyan">待审核</span> @{{# } }}
            @{{# if(d.status == 2){ }} <span class="layui-badge layui-bg-gray">已拒绝</span> @{{# } }}
            @{{d.tag}}
            @{{# if(d.is_top == 1){ }} <span class="layui-badge layui-bg-black">置顶</span> @{{# } }}
        </script>
        <script type="text/html" id="options">
            <div class="layui-btn-group">
                <a href="/forumDetail/@{{d.id}}" target ="_blank" class="layui-btn layui-btn-xs">详情</a>
                @can('forumType.edit')
                <a data-url="{{route("forum.edit")}}" lay-event="edit" class="layui-btn layui-btn-xs layui-btn-normal">设置</a>
                @endcan
                @can('forumType.delete')
                <a data-url="{{route("forum.delete")}}" lay-event="del" class="layui-btn layui-btn-xs layui-btn-danger">删除</a>
                @endcan
            </div>
        </script>

    </div>

@endsection

@section('script')
    <script>
        layui.use(['table', 'layer', 'jquery'], function () {
            $ = layui.jquery;
            var table = layui.table;
            table.render({
                elem: '#tableData'
                , url: '{{route("forum.list")}}'
                , cols: [[
                    {field: 'id', title: 'ID', sort: true, width: 60}
                    , {field: 'auth', title: '发布者', width: 180, templet: function (d) {
                            return '<img src="' + d.get_user.head_img.url + '" style="width: 30px;"> ' + d.get_user.name
                        }
                    }
                    , {field: 'title', title: '帖子标题', minWidth: 200}
                    , {field: 'views_num', title: '浏览量', sort: true, width: 100}
                    , {field: 'type', title: '分类', width: 100, templet: function (d) {
                            return d.get_type.title
                        }
                    }
                    , {field: 'tag', title: '标签', toolbar: '#tag', width: 180}
                    , {field: 'created_at', title: '创建时间', width: 180}
                    , {fixed: 'right', title: '操作', align: 'center', width: 150, toolbar: '#options'}
                ]]
                , id: 'myReload'
                , page: true
            });
        });
    </script>
@endsection